package thirdQuestion;

import java.io.*;
import java.net.Socket;
import java.util.Scanner;

public class Client {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Socket socket = null;
        ObjectOutputStream oos = null;
        BufferedReader br = null;
        try {
            socket = new Socket("localhost",8888);
            System.out.println("已经连接上了服务端。。。");

            oos = new ObjectOutputStream(socket.getOutputStream());
            br = new BufferedReader(new InputStreamReader(socket.getInputStream()));

            System.out.println("请登录:");
            System.out.println("请输入用户名：");
            String name = scanner.next();
            System.out.println("请输入密码：");
            String password = scanner.next();

            oos.writeObject(new User(name,password));
            oos.flush();

            String info=br.readLine();
            System.out.println(info);
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if (socket!=null){
                try {
                    socket.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
